﻿using Common.DTOS;
using Common.Net;
using Common.Tools;
using KCPServer.Core.Net.Info;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace KCPServer.Core.Net
{
    public partial class NetManager
    {
        private void RegisterCallback()
        {
            msgDic.Add(Common.Net.RequestType.CLogin, OnClogin);
            msgDic.Add(Common.Net.RequestType.ShutDown, OnShutDown);
        }

        private void OnShutDown(MsgInfoPack pack)
        {
            NServer.Instance.ShutDownById(pack.clientPeer.clientId);
            Console.WriteLine("Shutdown:"+pack.clientPeer.clientId);
        }

        private void OnClogin(MsgInfoPack pack)
        {
          if(pack.msg.vo is JObject)
            {
                var jo = pack.msg.vo as JObject;
                var dto = jo.ToObject<CLoginDto>();
                Console.WriteLine("OnCLogin:" + dto.account + " id:" );
            }
           
            var vo = new SLoginDto()


            {

                id = (uint)pack.clientPeer.clientId,
                userName = "test",
            };
            Console.WriteLine("OnCLogin" + vo.id);
            //相应的消息返回给客户端
            pack.clientPeer.send(RequestType.SLogin, vo);
        }
    }
}
